// 第一步：引入相关文件
import 'package:flutter/material.dart';
import 'package:flutterone/page/home/home.dart';
import 'package:flutterone/page/category/category.dart';
import 'package:flutterone/page/me/me.dart';

// 第二步：创建一个有状态的Tabs 组件
class Tabs extends StatefulWidget {
  Tabs({Key? key}) : super(key: key);
  @override
  _TabsState createState() => _TabsState();
}
class _TabsState extends State<Tabs> {
  //记录当前tabbar点击的下标
  int _currentIndex=0;
  //存放tabbar
   final List _pageList =[
    HomePage(),
    CategoryPage(),
    SettingPage()
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      // 设置需要显示的内容。
      body: _pageList[_currentIndex],
      //创建tabbar
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex,
        onTap: (int index) {
          setState(() {
            _currentIndex = index;
          });
        },
        //设置图标尺寸
        iconSize: 30,
        //设置选中图标的颜色
        fixedColor: Colors.red,
        backgroundColor: Colors.white,
        //设置item
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(icon: Icon(Icons.home,), label: "首页"),
          BottomNavigationBarItem(icon: Icon(Icons.category), label: "分类"),
          BottomNavigationBarItem(icon: Icon(Icons.person), label: "我的"),
        ],
      ),
    );
  }
}